/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package inquiry;

import item.Item;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Date;
import javax.persistence.*;
import myJPA.Model;
import user.Employee;

/**
 *
 * @author Nacer Khalil
 */

@Entity
@Table(name="inquiry")
@NamedQuery(name="findInquiry", query="select id from Inquiry id where id =:id")
@Inheritance(strategy=InheritanceType.JOINED)
public class Inquiry extends Model{
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    private int id;
    private String message;
    private String response;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    
    @ManyToOne
    @JoinColumn(name = "emp_id")
    private Employee employee;
    
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        int oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public Inquiry() {
        super();
    }

    
    
    public Inquiry(String message, Date date) {
        super();
        this.message = message;
        this.date = date;
        this.response=null;
    }
    

    /**
     * @return the message
     */
    public String getMessage() {
        return message;
    }

    /**
     * @param message the message to set
     */
    public void setMessage(String message) {
        String oldMessage = this.message;
        this.message = message;
        changeSupport.firePropertyChange("message", oldMessage, message);
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @return the employee
     */
    public Employee getEmployee() {
        return employee;
    }

    /**
     * @param employee the employee to set
     */
    public void setEmployee(Employee employee) {
        Employee oldEmployee = this.employee;
        this.employee = employee;
        changeSupport.firePropertyChange("employee", oldEmployee, employee);
    }

    /**
     * @return the response
     */
    public String getResponse() {
        return response;
    }

    /**
     * @param response the response to set
     */
    public void setResponse(String response) {
        String oldResponse = this.response;
        this.response = response;
        changeSupport.firePropertyChange("response", oldResponse, response);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Inquiry other = (Inquiry) obj;
        if (this.id != other.id) {
            return false;
        }
        if ((this.message == null) ? (other.message != null) : !this.message.equals(other.message)) {
            return false;
        }
        if ((this.response == null) ? (other.response != null) : !this.response.equals(other.response)) {
            return false;
        }
        if (this.date != other.date && (this.date == null || !this.date.equals(other.date))) {
            return false;
        }
        if (this.employee != other.employee && (this.employee == null || !this.employee.equals(other.employee))) {
            return false;
        }
        
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        return hash;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
    
}
